home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
sortc.arc
/
COPY.C
next >
Wrap
Text File
|
1987-06-19
|
2KB
|
78 lines
/*
* c o p y . c
*/
#ifdef DOCUMENTATION
title copy Copy a Given Number of Bytes
index Copy a given number of bytes
synopsis
.s.nf
char *
copy(out, in, nbytes)
char *out; /* Output vector */
char *in; /* Input vector */
unsigned int count; /* Bytes to copy */
.s.f
Description
Copy the indicated number of bytes from the input area
to the output area. Return a pointer to the first free
byte in the output area. (I.e., &out[count]).
The copying will be faster if out and in are either both
even or both odd addresses.
Bugs
Warning, this routine "understands" pdp-11 address conventions.
#endif
#define SHIFT 1
#define LOWBIT 01
char *copy(out, in, count)
register char *out;
register char *in;
register unsigned int count;
/*
* Copy a given number of bytes
*/
{
if (count != 0)
{
#ifdef SHIFT
if (count > 10)
{
/*
* Try to optimize
*/
if ((((unsigned int) in) & LOWBIT) != 0)
{
*out++ = *in++;
count--;
}
if ((((unsigned int) out) & LOWBIT) == 0)
{
count >>= SHIFT; /* Get a word count */
do
{
*((int *)out)++ = *((int *)in)++;
} while (--count != 0);
goto exit;
}
}
#endif
/*
* Here for small copies, strange machines, and copies where
* the output buffer isn't the same parity as the input buffer.
*/
do
{
*out++ = *in++;
} while (--count != 0);
}
exit: return (out);
}